package com.library.action;

import java.util.List;

import com.library.common.SPageBean;
import com.library.model.Bookinfo;
import com.library.service.AllBookService;

public class AllBookAction extends BaseAction{
	private AllBookService allBookService;
	private Bookinfo book;
	private List<Bookinfo> books;

	public AllBookService getAllBookService() {
		return allBookService;
	}

	public void setAllBookService(AllBookService allBookService) {
		this.allBookService = allBookService;
	}
	
	public Bookinfo getBook() {
		return book;
	}

	public void setBook(Bookinfo book) {
		this.book = book;
	}

	public String toBookList() throws Exception{
		Bookinfo b = allBookService.checkBook(book);
		int offset = 0;
		if(request.getParameter("pager.offset")==null){
			offset = 0;
		}
		else{
			offset = Integer.parseInt(request.getParameter("pager.offset"));
		}
		SPageBean spb = new SPageBean();
		spb.setOffset(offset);
		spb.setPageSize(4);
		books = allBookService.getAllBooksByPage(spb);
		request.setAttribute("SPB", spb);
		request.setAttribute("book", b);
		return "list";
	}
	public String toQuery() throws Exception{
		int offset = 0;
		if(request.getParameter("pager.offset")==null){
			offset = 0;
		}
		else{
			offset = Integer.parseInt(request.getParameter("pager.offset"));
		}
		SPageBean spb = new SPageBean();
		System.out.println(offset);
		spb.setOffset(offset);
		spb.setPageSize(4);
		books = allBookService.queryBook(spb, book);
		request.setAttribute("SPB", spb);	
		return "list";
	}
}
